#pragma once
#include<iostream>
#include<pthread.h>

namespace my_task
{
    //任务(计算)
    class Task
    {
    private:
        int _x;
        int _y;
        char _op; //"+-*/%"

        int Run()
        {
            int ret = 0;

            switch(_op)
            {
            case '+':
                ret = _x + _y;
                break;
            case '-':
                ret = _x - _y;
                break;
            case '*':
                ret = _x * _y;
                break;
            case '/':
                ret = _x / _y;
                break;
            case '%':
                ret = _x / _y;
                break;
            default:
                std::cout << "bug!" << std::endl;
                break;
            }            
            return ret;
        }

    public:
        Task()
        {}
        Task(int x, int y, char op):_x(x), _y(y), _op(op)
        {}
        void Show()
        {
            int ret = Run();
            std::cout << "消费者" << pthread_self() <<"处理了一个任务：" << _x << _op << _y << "=" << ret << std::endl;
        }
        //仿函数(回调Run)
        int operator()()
        {
            return Run();
        }
    };
}

